export default {
    methods: {
        jump(to) {
            if (this.$router) {
                this.$router.push(to)
            }
        },
        isIpx() {
            return weex && (weex.config.env.deviceModel === 'iPhone10,3' || weex.config.env.deviceModel === 'iPhone10,6');
        },
        commonApi(info) {
            let stream = weex.requireModule('stream');
            let { baseUrl, url, method, type = "json", params, title, headers = {} } = info;
            baseUrl = baseUrl ? baseUrl : "http://localhost:5757/heyushuo";
            // if (process.env.NODE_ENV !== "development") {
            //     baseUrl = 'http://122.51.140.204:5757/heyushuo'
            // }

            return new Promise((resolve, reject) => {
                stream.fetch({
                    method,
                    type,
                    url:baseUrl + url,
                    body: params,
                    headers
                }, (response) => {
                    if (!response.ok) {
                        reject(response.data)
                        console.error(title + '调用成功')
                    } else {
                        resolve(response.data)
                        console.log(title + '调用成功')
                    }
                })
            })

        }

    }
}
